/**
 * 报表设计公司(2011)
 */
package com.reportgear.report.model.cell.painter;

import java.util.HashMap;
import java.util.Map;

import com.reportgear.report.core.cell.painter.impl.SalarItemObjectPainter;
import com.reportgear.report.core.cell.painter.impl.SalarMainObjectPainter;
import com.reportgear.report.model.cell.value.salary.SalaryItemObject;
import com.reportgear.report.model.cell.value.salary.SalaryMainObject;

/**
 * 单元格绘制器管理器
 * 
 * @version 1.0 2011-3-22
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since ANNCSR 2.0
 */
public enum CellPainterManager {
	INSTANCE;

	// 绘制器缓存
	private Map<Class<?>, CellPainter> painters = new HashMap<Class<?>, CellPainter>();

	CellPainterManager() {
		// 注册绘制器
		painters.put(Object.class, new DefaultCellPainter());
		painters.put(SalaryItemObject.class, new SalarItemObjectPainter());
		painters.put(SalaryMainObject.class, new SalarMainObjectPainter());
	}

	/**
	 * 根据类获取绘制器
	 * 
	 * @param clazz
	 *            类
	 * @return 绘制器
	 */
	public CellPainter getCellPainter(Class<?> clazz) {
		CellPainter editor = painters.get(clazz);

		if (editor == null) {
			return painters.get(Object.class);
		} else {
			return editor;
		}
	}

	/**
	 * 根据对象获取绘制器
	 * 
	 * @param o
	 *            对象
	 * @return 绘制器
	 */
	public CellPainter getCellPainter(Object o) {
		// Class<?> clazz = (o == null ? Object.class : o.getClass());

		return this.getCellPainter(o.getClass());
	}
}
